package com.dragon.tools.pojo;

import java.util.*;

public class MyRequestBody {

    private String databaseName;
    private String tabName;
    private String tabComment;
    private String tabType;
    private String columnName;
    private String columnType;
    private String columnComment;
    private String parColumn;
    private String parType;
    private String parComm;
    private String delimited = ",";
    private String storeType = "TEXTFILE";
    private String hdfsPath = "";

    // 判断值
    public Map<String, String> judgeValues(MyRequestBody b, MyResponseBody response) {
        Map<String, String> map = new HashMap<>();
        String databaseName = b.getDatabaseName();
        String tabName = b.getTabName();
        String tabType = b.getTabType();
        String parColumn = b.getParColumn();
        String parType = b.getParType();
        String delimited = b.getDelimited();
        String storeType = b.getStoreType();

        map.put("databaseName", databaseName);
        map.put("tabName", tabName);
        map.put("tabType", tabType);
        map.put("parColumn", parColumn);
        map.put("parType", parType);
        map.put("delimited", delimited);
        map.put("storeType", storeType);

        for (String key : map.keySet()) {
            String valTrim = map.get(key).trim();
            if ("".equals(valTrim) || valTrim == null) {
                response.setResultCode("401"); // 未输入值错误
                response.setStatus("[" + key + "]不能为空");
            }
        }


        // 对字段进行判断处理 名称与类型
        String columnName = b.getColumnName();
        String columnType = b.getColumnType();
        System.out.println("columnName : "+b.getColumnName());
        System.out.println("columnType : "+b.getColumnType());
        System.out.println("columnType : "+b.getColumnComment());
        if (!"".equals(columnName) && !"".equals(columnType) && columnType != null && columnName != null) {
            String[] columnNames = columnName.split(",");
            String[] columnTypes = columnType.split(",");
            System.out.println("columnNamesLength:"+columnNames.length);
            System.out.println("columnTypesLength:"+columnTypes.length);
            System.out.println("ColumnCommentLength:"+b.getColumnComment().split(",").length);
            for (String s : columnNames) {
                if ("".equals(s.trim()) || s == null) {
                    response.setResultCode("401"); // 未输入值错误
                    response.setStatus("[columnName]不能为空");
                }
            }
            for (String s : columnTypes) {
                if ("".equals(s.trim()) || s == null) {
                    response.setResultCode("401"); // 未输入值错误
                    response.setStatus("[columnType]不能为空");
                }
            }
        } else {
            response.setResultCode("401"); // 未输入值错误
            response.setStatus("[字段名称]或[字段类型]不能为空");
        }

        return map;
    }

    public String getDatabaseName() {
        return databaseName;
    }

    public void setDatabaseName(String databaseName) {
        this.databaseName = databaseName;
    }

    public String getTabName() {
        return tabName;
    }

    public void setTabName(String tabName) {
        this.tabName = tabName;
    }

    public String getTabComment() {
        return tabComment;
    }

    public void setTabComment(String tabComment) {
        this.tabComment = tabComment;
    }

    public String getTabType() {
        return tabType;
    }

    public void setTabType(String tabType) {
        this.tabType = tabType;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getColumnType() {
        return columnType;
    }

    public void setColumnType(String columnType) {
        this.columnType = columnType;
    }

    public String getColumnComment() {
        return columnComment;
    }

    public void setColumnComment(String columnComment) {
        this.columnComment = columnComment;
    }

    public String getParColumn() {
        return parColumn;
    }

    public void setParColumn(String parColumn) {
        this.parColumn = parColumn;
    }

    public String getParType() {
        return parType;
    }

    public void setParType(String parType) {
        this.parType = parType;
    }

    public String getParComm() {
        return parComm;
    }

    public void setParComm(String parComm) {
        this.parComm = parComm;
    }

    public String getDelimited() {
        return delimited;
    }

    public void setDelimited(String delimited) {
        this.delimited = delimited;
    }

    public String getStoreType() {
        return storeType;
    }

    public void setStoreType(String storeType) {
        this.storeType = storeType;
    }

    public String getHdfsPath() {
        return hdfsPath;
    }

    public void setHdfsPath(String hdfsPath) {
        this.hdfsPath = hdfsPath;
    }
}
